<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*,app.stock.common.*,app.stock.web.*, app.stock.server.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=Transaction.label%></title>
<%@ include file="head.jsp"%>
<%@ include file="js.jsp"%>
<script type="text/javascript">
    function onQuery(){
    	submitForm('query_form',['page=transaction_list.jsp','action=query']);      
    }
</script>
</head>
<body>
<%@ include file="bodyhead.jsp"%>
<div align="center">
<form method="post" name="query_form" action="StockCtrl?page=transaction_list.jsp&action=query">
    <table>
		<tr>
			<td><label><%=Transaction.typeLabel%></label></td>
			<td><select size="1" id="<%=Transaction.typeName%>" name="<%=Transaction.typeName%>">				
				<%
					for (int i = 0; i < TransactionTypes.values2.length; i++) {
				%>				
				<option value="<%=TransactionTypes.values2[i]%>"><%=TransactionTypes.values2[i]%></option>
				<%     
					}		
				%>		
			</select></td>
			<td><label><%=Transaction.codeLabel%></label></td>
			<td><input name="<%=Transaction.codeName%>"></input></td>
			<td><input type="submit" value="<%=Constants.label_operationQuery%>" onClick="submitForm('query_form',['page=transaction_list.jsp','action=query'])"></input></td>
			<td><input type="button" value="<%=Constants.label_operationAdd%>" onClick="submitForm('query_form',['page=transaction_list.jsp','action=add'])"></input></td>
		</tr>
    </table>
</form>
<%      
    List txList = (List) request.getAttribute(WebConstants.key_attr_txList);
    request.removeAttribute(WebConstants.key_attr_txList);
    int txNum = 1;
    if(request.getAttribute(WebConstants.key_attr_txNum)!= null){
        txNum = (Integer)request.getAttribute(WebConstants.key_attr_txNum);
    }
    if (txList == null) {
    	StockManager mgr = new StockManager();
        txList = mgr.getTransactionList(null);
        txNum = txList.size();
    }
%>
<div align="center">
    <form method="post" name="paging_form" action="StockCtrl?page=transaction_list.jsp&action=query">
       <% 
       int pageNum = (int)Math.ceil(((double)txNum / Constants.pageSize));
       for(int i = 0; i < pageNum; i++){
       %>
       <a href="StockCtrl?page=transaction_list.jsp&action=query&pageIndex=<%=i+1%>"><%=i+1%></a>
       <% 
       } 
       %>
       <!--a> previous </a>
       <a> next </a>
       <input value = ""></input-->
    </form>
</div>
</div>
<div align="center">
<table cellspacing="1" cellpadding="1" border="1">
	<tr>
		<td><%=Constants.label_sequence%></td>
		<td><%=Transaction.dateLabel%></td>
		<td><%=Transaction.typeLabel%></td>
		<td><%=Transaction.codeLabel%></td>
		<td><%=Transaction.nameLabel%></td>
		<td><%=Transaction.priceLabel%></td>
		<td><%=Transaction.amountLabel%></td>
		<td><%=Transaction.sum1Label%></td>
		<td><%=Transaction.shouxufeiLabel%></td>
		<td><%=Transaction.yinhuashuiLabel%></td>
		<td><%=Transaction.guohufeiLabel%></td>
		<td><%=Transaction.price2Label%></td>
		<td><%=Transaction.sum2Label%></td>
		<td><%=Transaction.currentAmountLabel%></td>
		<td><%=Transaction.currentCashLabel%></td>
		<td colspan="2"><%=Constants.label_operation%></td>
	</tr>
	<%
	    float ciLun = 0;
		for (int i = 1; i <= txList.size(); i++) {
			Transaction tx = (Transaction) txList.get(i - 1);
			ciLun += tx.sum2;
	%>
	<tr>
		<td><%=i%></td>
		<td><%=Util.toDefaultDateFormat(tx.date)%></td>
		<td><%=tx.type%></td>
		<td><%=tx.code%></td>
		<td><%=tx.name%></td>
		<td><%=tx.price%></td>
		<td><%=tx.amount%></td>
		<td><%=tx.sum1%></td>
		<td><%=tx.shouxufei%></td>
		<td><%=tx.yinhuashui%></td>
		<td><%=tx.guohufei%></td>
		<td name="<%=Transaction.price2Name%>"><%=tx.price2%></td>
		<td><%=tx.sum2%></td>
		<td><%=tx.currentAmount%></td>
		<td><%=tx.currentCash%></td>
		<td><a href="StockCtrl?page=transaction_list.jsp&action=update&id=<%=tx.id%>"><%=Constants.label_operationEdit%></a></td>
        <td><a href="StockCtrl?page=transaction_list.jsp&action=delete&id=<%=tx.id%>"
	           onclick="javascript:return confirm('<%=Constants.label_confirm_operationDelete%>')"><%=Constants.label_operationDelete%>
	        </a>
	    </td>
	</tr>
	<%
	   		if(tx.currentAmount == 0 && request.getParameter(Transaction.codeName)!=null){
		   		%>
				<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>此轮盈亏</td>
				<td name="<%=Transaction.price2Name%>"><%=ciLun%></td>
				<td></td>
				<td></td>
				</tr>
		   		<%
		   		ciLun=0;
	   		}
		}
	%>
</table>
<script type="text/javascript">
    var elemNames = ['<%=Transaction.price2Name%>'];
    toFixedFloatByName(elemNames,'td');
</script>
<a href="StockCtrl?action=add&page=transaction_list.jsp"><%=Constants.label_operationAdd%></a>
</div>
<%
	if(request.getAttribute(WebConstants.key_attr_stockList)!=null){
%>
<%@ include file="summary_table.jsp"%>
<% }%>
</body>
</html>